package com.basic.emg.controller;



import com.basic.emg.model.BaseModel;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * web层通用数据处理
 * 
 * @author corner
 */
public class BaseController
{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 仅支持字母、数字、下划线、空格、逗号、小数点（支持多个字段排序）
     */
    public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";


    public static void startPage(BaseModel model)
    {
        Integer pageNum = model.getPageNum();
        Integer pageSize = model.getPageSize();
        String sortParam = model.getSortParam();
        PageHelper.startPage(pageNum, pageSize, sortParam);
    }

 /*   public static void startPage(BaseModel model)
    {
        Integer pageNum = model.getPageNum();
        Integer pageSize = model.getPageSize();
        String sortParam = model.getSortParam();
        String orderBy = "";
        if(StringUtils.isNotBlank(sortParam) ){
            sortParam = toSnakeCase(sortParam);
            boolean isDesc = model.isDesc();
            String sort = "desc";
            if(!isDesc){
                sort = "asc";
            }

            if(StringUtils.isNotEmpty(sortParam)){
                orderBy = sortParam + " " + sort;
            }
        }


        PageHelper.startPage(pageNum, pageSize, orderBy);
    }*/

    public static String toSnakeCase(String camelCaseStr) {
        return camelCaseStr.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
    }


}
